package lab03.test01.test01;

import java.io.*;

public class Test01 {
    public static void main(String[] args) {
        //1.指定文件的路径
        File myfile;
        myfile = new File("D:\\Hello.txt");
        //String path = "D://Hello.txt";

        //2.文件名由命令提示行给出，且为绝对路径名
        System.out.println("文件的绝对路径："+myfile.getAbsolutePath());

        //3.读取并输出指定文件的内容
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(myfile));
            String line = "";//一行一行读取，读取的数据放在line中

            try {
                while ((line = reader.readLine())!=null){
                    System.out.println(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
